/**
 * Project Name:gc.sms.mvn
 * File Name:RoleController.java
 * Package Name:com.clps.dev.sms.controller
 * Date:2018年11月18日下午3:35:56
 * Copyright (c) 2018, longbiosphere@163.com All Rights Reserved.
 *
 */
package com.clps.dev.sms.controller.sm;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.clps.dev.sms.common.result.ResponseResult;
import com.clps.dev.sms.entity.sm.Role;
import com.clps.dev.sms.service.sm.IRoleService;
 


/**
 * ClassName: RoleController <br/>
 * Description:  
 * date: 2018年11月18日 下午3:35:56 <br/>
 *
 * @author long.ma
 * @version V1.0
 * @since JDK 1.8
 */
@Controller
@RequestMapping(value="/role")
public class RoleController {
	
	@Resource
	private IRoleService roleService;
Logger logger =Logger.getLogger(RoleController.class);
	 

	 
	/**
	 * 
	 * showRole: 显示角色
	 *
	 * @author long.ma
	 * @param model
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/listRole")
	public String showRole(Model model) {
		ResponseResult<Role> responseResult=roleService.queryAllRole();
		@SuppressWarnings("unchecked")
		List<Role> roles = (List<Role>) responseResult.getData();
		model.addAttribute("roles", roles);

		return "sm/role_list";
	}
	
	/**
	 * 
	 * deleteRole:  删除角色
	 * 
	 * @author long.ma
	 * @param role
	 * @param request
	 * @param model
	 * @return
	 * @since JDK 1.8
	 *
	@RequestMapping(value = "/deleteRole", method = RequestMethod.GET)
	public String deleteRole(Role role,HttpServletRequest request, Model model) {
		roleService.deleteRole(role);

		List<Role> roles = roleService.queryAllRoles();
		model.addAttribute("roles", roles);
		return "sm/role_list";
	}
	*/
	
	/**
	 * 
	 * creatRole: 创建角色
	 *
	 * @author long.ma
	 * @param request
	 * @param model
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/creatRole")
	public String creatRole(HttpServletRequest request, Model model) {
		Role role=new Role();
		roleService.addRole(role);
		@SuppressWarnings("unchecked")
		List<Role> roles = (List<Role>)roleService.queryAllRole().getData();
		model.addAttribute("roles", roles);
		return "sm/role_list";
	}
	
	/**
	 * 
	 * queryRoleById: 通过id查询角色
	 *
	 * @author long.ma
	 * @param request
	 * @param model
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/queryRole", method = RequestMethod.POST)
	public String queryRoleById(HttpServletRequest request, Model model) {
		int roleId = Integer.parseInt(request.getParameter("roleId"));
		Role role = (Role) roleService.queryRole(roleId).getData();
		model.addAttribute("roles", role);

		return "sm/role_query";
	}
	
	/**
	 * 
	 * updateRole: 修改角色
	 *
	 * @author long.ma
	 * @param role
	 * @param request
	 * @param model
	 * @return
	 * @since JDK 1.8
	 */
	@RequestMapping(value = "/updateRole")
	public String updateRole(Role role,HttpServletRequest request, Model model) {
		roleService.editRole(role);
		model.addAttribute("role", role);

		return "sm/role_update";
	}

	
	
	
	
	
	
	
	
	
	
	
	
	

}
